<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-yjIntegral-edit" th:object="${yjIntegral}">
            <input id="behaviorId" name="behaviorId" th:field="*{behaviorId}"  type="hidden">
            <input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeIds"/>
            <div class="form-group">
                <label class="col-sm-3 control-label">部门名称：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" readonly="true" id="treeNames" th:field="*{deptName}">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">类别名称：</label>
                <div class="col-sm-8">
                    <input id="behaviorCategory" name="behaviorCategory" th:field="*{behaviorCategory}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">行为标题：</label>
                <div class="col-sm-8">
                    <input id="behaviorTitle" name="behaviorTitle" th:field="*{behaviorTitle}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">行为内容：</label>
                <div class="col-sm-8">
                    <!--<input id="behaviorContent" name="behaviorContent" th:field="*{behaviorContent}" class="form-control" type="text">-->
                    <textarea id="behaviorContent" name="behaviorContent" class="form-control" th:text="*{behaviorContent}"></textarea>
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">申请方式：</label>
                <div class="col-sm-8">
                    <!--<input id="shenQingFangShi" name="shenQingFangShi" th:field="*{shenQingFangShi}" class="form-control" type="text">-->
                    <select name="shenQingFangShi" class="form-control m-b-none" th:value="*{shenQingFangShi}">
                        <!--<option value="">-&#45;&#45;请选择-&#45;&#45;</option>-->
                        <option value="0">每天一次</option>
                        <option value="1">每周一次</option>
                        <option value="2">每月一次</option>
                        <option value="3">每季一次</option>
                        <option value="4">每年一次</option>
                        <option value="5">无限制</option>
                        <option value="6">仅限一次</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">积分类型：</label>
                <div class="col-sm-8">
                    <input id="typeId" name="typeId" th:field="*{typeId}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">积分菜单：</label>
                <div class="col-sm-8">
                    <select name="menuId" th:value="*{menuId}" th:with="type=${@type.getTypeName('3')}" class="form-control m-b-none">
                        <option value="">所有</option>
                        <option th:each="menu : ${type}" th:text="${menu.typeName}" th:value="${menu.menuId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">最多奖励积分：</label>
                <div class="col-sm-8">
                    <input id="zuiDuoIntegral" name="zuiDuoIntegral" th:field="*{zuiDuoIntegral}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">最少奖励积分：</label>
                <div class="col-sm-8">
                    <input id="zuiShaoIntegral" name="zuiShaoIntegral" th:field="*{zuiShaoIntegral}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">积分分级：</label>
                <div class="col-sm-8">
                    <input id="integralFenJi" name="integralFenJi" th:field="*{integralFenJi}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">已完成次数：</label>
                <div class="col-sm-8">
                    <input id="yiWanChengCiShu" name="yiWanChengCiShu" th:field="*{yiWanChengCiShu}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">使用状态：</label>
                <div class="col-sm-8">
                    <!--<div class="form-control-static" th:text="*{status == 0 ? '使用中' : '停用'}" th:class="*{status == 0 ? 'label label-primary' : 'label label-danger'}">
                    </div>-->
                    <div class="onoffswitch">
                    <input type="checkbox" th:checked="!*{status}" class="onoffswitch-checkbox" id="status" name="status">
                    <label class="onoffswitch-label" for="status">
                        <span class="onoffswitch-inner"></span>
                        <span class="onoffswitch-switch"></span>
                    </label>
                </div>
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">创建时间：</label>
                <div class="col-sm-8">
                    <input id="createTime" name="createTime" th:field="*{createTime}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">修改时间：</label>
                <div class="col-sm-8">
                    <input id="updateTime" name="updateTime" th:field="*{updateTime}" class="form-control" type="text" disabled>
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">备注信息：</label>
                <div class="col-sm-8">
                    <textarea id="remark" name="remark" class="form-control" th:text="*{remark}"></textarea>
                </div>
            </div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script th:src="@{/ajax/libs/select/select2.js}"></script>
    <script type="text/javascript">

        /*用户管理-新增-选择部门树*/
        function selectDeptTree() {
            var treeId = $("#treeIds").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeIds").val();
            var url = ctx + "integral/xwIntegral/selectIntegralMenuDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: ctx + "integral/xwIntegral/selectIntegralMenuDeptTree/" + deptId,
                callBack: doSubmit2
            };
            $.modal.openOptions(options);
        }
        function doSubmit2(index, layero){
            var body = layer.getChildFrame('body', index);
            $("#treeIds").val(body.find('#treeId').val());
            $("#treeNames").val(body.find('#treeName').val());
            layer.close(index);
        }


        var prefix = ctx + "integral/yjIntegral"
		$("#form-yjIntegral-edit").validate({
			rules:{
                behaviorCategory:{
					required:true,
				},
			}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	           // $.operate.save(prefix + "/edit", $('#form-yjIntegral-edit').serialize());
                edit();
	        }
	    }

        function edit() {
            var deptId = $("input[name='deptId']").val();
            var deptName = $("input[name='deptName']").val();
            var behaviorId = $("input[name='behaviorId']").val();
            var behaviorCategory = $("input[name='behaviorCategory']").val();
            var behaviorTitle = $("input[name='behaviorTitle']").val();
            var behaviorContent = $("textarea[name='behaviorContent']").val();
            var shenQingFangShi = $("select[name='shenQingFangShi'] option:selected").val();
            var zuiDuoIntegral = $("input[name='zuiDuoIntegral']").val();
            var zuiShaoIntegral = $("input[name='zuiShaoIntegral']").val();
            var integralFenJi = $("input[name='integralFenJi']").val();
            var status = $("input[name='status']").is(':checked') == true ? 0 : 1;
            var remark = $("textarea[name='remark']").val();
            var menuId = $("select[name='menuId'] option:selected").val();
            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "integral/yjIntegral" + "/edit",
                data : {
                    "deptId": deptId,
                    "deptName": deptName,
                    "behaviorId":behaviorId,
                    "behaviorCategory": behaviorCategory,
                    "behaviorTitle": behaviorTitle,
                    "behaviorContent": behaviorContent,
                    "shenQingFangShi": shenQingFangShi,
                    "zuiDuoIntegral": zuiDuoIntegral,
                    "zuiShaoIntegral": zuiShaoIntegral,
                    "integralFenJi": integralFenJi,
                    "remark": remark,
                    "status": status,
                    "menuId": menuId
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.saveSuccess(data);
                }
            });
        }
    </script>
</body>
</html>
